#include "stdafx.h"

gluiApp::gluiApp(int w=800, int h=800)
{
	view_rotate[0] = 1;
	view_rotate[1] = 0;
	view_rotate[2] = 0;
	view_rotate[3] = 0;

	view_rotate[4] = 0;
	view_rotate[5] = 1;
	view_rotate[6] = 0;
	view_rotate[7] = 0;

	view_rotate[8] = 0;
	view_rotate[9] = 0;
	view_rotate[10] = 1;
	view_rotate[11] = 0;

	view_rotate[12] = 0;
	view_rotate[13] = 0;
	view_rotate[14] = 0;
	view_rotate[15] = 1;

	obj_pos[0] = 0.0f;
	obj_pos[1] = 1.5f;
	obj_pos[2] = 0.0f;

	_width = w;
	_height = h;


    
	 
}
void gluiApp::createUI()
{
	//GLUI
	glui = GLUI_Master.create_glui( "GLUI", 0, 850, 40); 

	_spinner_count = 0;

	raycaster_panel = new GLUI_Panel( glui, "Parameters" );
	currentP = raycaster_panel;
}

int gluiApp::getHeight()
{
	return _height;
}
int gluiApp::getWidth()
{
	return _width;
}


float* gluiApp::getRotationMatrix()
{
	return view_rotate;
}

float* gluiApp::getTranslationVector()
{
	return obj_pos;
}

void gluiApp::setidle(void (*f)(void))
{
	GLUI_Master.set_glutIdleFunc( f );
}

void gluiApp::setWindowID(int window_id)
{
	glui->set_main_gfx_window( window_id );
	_windowID = window_id;
}

int gluiApp::getWindowID()
{
	return _windowID;
}

//void gluiApp::addTranslationX(char* translationxname)
//{
//	GLUI_Translation *trans_x = new GLUI_Translation(glui, "Objects X", GLUI_TRANSLATION_X, obj_pos );
//	trans_x->set_speed( .005 );
//
//}
//
//
//void gluiApp::addTranslationY(char* translationyname)
//{
//	//new GLUI_Column( glui, false );
//	GLUI_Translation *trans_y = new GLUI_Translation( glui, "Objects Y", GLUI_TRANSLATION_Y, &obj_pos[1] );
//	trans_y->set_speed( .005 );
//	
//}
//
//void gluiApp::addTranslationZ(char* translationzname)
//{
//	//new GLUI_Column( glui, false );
//	GLUI_Translation *trans_z = new GLUI_Translation( glui, "Objects Z", GLUI_TRANSLATION_Z, &obj_pos[2] );
//	trans_z->set_speed( .005 );
//}
void gluiApp::addIntValue(char* name, int *val)
{
	_parameter_int.insert(std::pair<std::string,int*>(name,val)); //default 0

}

void gluiApp::addSpinner(char* spinnername, float limitMin, float limitMax, float initValue=0)
{
	//spinner
	_parameter_float.insert(std::pair<std::string,float>(spinnername,initValue)); //default 0
	_spinnerGUI[_spinner_count] = new GLUI_Spinner( currentP, spinnername, this->getPointer2Data(spinnername));
	_spinnerGUI[_spinner_count]->set_float_limits( limitMin, limitMax );
    _spinnerGUI[_spinner_count]->set_alignment( GLUI_ALIGN_RIGHT );
	//_spinnerGUI[_spinner_count]->set_float_value(

	_spinner_count++;
}

void gluiApp::addSpinnerToPannel(char* spinnername, GLUI_Panel *panel, float limitMin, float limitMax, float initValue)
{
	//spinner
	_parameter_float.insert(std::pair<std::string,float>(spinnername,initValue)); //default 0
	_spinnerGUI[_spinner_count] = new GLUI_Spinner( panel, spinnername, this->getPointer2Data(spinnername));
	_spinnerGUI[_spinner_count]->set_float_limits( limitMin, limitMax );
    _spinnerGUI[_spinner_count]->set_alignment( GLUI_ALIGN_RIGHT );
	//_spinnerGUI[_spinner_count]->set_float_value(

	_spinner_count++;
}
void gluiApp::addCheckbox(char* checkboxname)
{
	_parameter_float.insert(std::pair<std::string,float>(checkboxname,0)); //default 0
	float *temp = getPointer2Data(checkboxname);
	int tempi = int(*temp);
	glui->add_checkbox(checkboxname,&tempi , 1);
	
}

float gluiApp::getData(char *name)
{
	std::map<std::string, float>::iterator iter = _parameter_float.begin();

	iter = _parameter_float.find(std::string(name));
	float val;
	//if(iter == 0) 
	//	{std::cout<<"can't find"<< name <<std::endl;}
	//else 
		val = iter->second;	
	return val;
}

int gluiApp::getDataInt(char *name)
{
	std::map<std::string, int*>::iterator iter = _parameter_int.begin();

	iter = _parameter_int.find(std::string(name));
	int* val;
	val = iter->second;	
	//std::cout<<*val<<std::endl;
	return *val;
}

float* gluiApp::getPointer2Data(char *name)
{
	std::map<std::string, float>::iterator iter = _parameter_float.begin();
	iter = _parameter_float.find(std::string(name));
	return &(iter->second);	
}

void gluiApp::currentPanel(GLUI_Panel* P)
{
	currentP = P;
}
